<template>
  <div class="stuList">
    <h2 class="header">学生列表</h2>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column fixed prop="_id" label="id" width="300">
      </el-table-column>
      <el-table-column prop="userName" label="用户名" >
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button 
          @click="$router.push(`/adminUser/edit/${scope.row._id}`)"
           type="text" size="small"
            >编辑</el-button
          >
          <el-button
          @click="remove(scope.row)" type="text" size="small">移除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  methods: {
     async fetchCats() {
    const res = await this.$http.get('/rest/adminUser')
    this.tableData= res.data
     },
     async remove(row) {
      this.$confirm(`确定要删除管理员${row.userName}吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then( async () => {
          const res = await this.$http.delete(`/rest/adminUser/${row._id}`)
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.fetchCats()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
     }
  },
  created() {
 this.fetchCats()
  },
   data() {
    return {
      tableData: [
        
      ],
    };
    model:{

    }
  },
};
</script>

<style>
.header {
  text-align: center;
}
</style>